<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\common\builder\TableBuilder;
use app\common\builder\TableFront;
use think\App;

class CollegeCate extends Base
{
    //主键，默认为id
    protected $pk = 'id';

    //主模型
    protected $model = '\app\common\model\CollegeCate';

    public function index()
    {
        return $this->setTable();
    }

    public function setTable()
    {
        //构建table
        $tableFront = TableFront::getInstance()
            ->addRow(['field' => 'id', 'title' => 'ID', 'sort' => true, 'width' => 80])
            ->addRow(['field' => 'title', 'title' => '名称', 'format' => 'input', 'modify' => 'add|edit'])
            ->addRow(['field' => 'icon', 'title' => '图标', 'format' => 'img','modify' => 'add|edit', 'width' => 100,
                'templet' => '<div><img class="thumbnail" src="{{d.icon}}"/></div>'
            ])
            ->addRow(['field' => 'sort', 'title' => '排序', 'format' => 'input', 'modify' => 'add|edit', 'width' => 100, 'templet' => '#sort_sort'])
            ->addRow(['field' => 'status', 'title' => '状态', 'templet' => '#status', 'width' => 120, 'unresize' => true])
            ->addRow(['field' => 'create_time', 'title' => '创建时间'])
            ->addRow(['field' => 'update_time', 'title' => '更新时间'])
            ->addRow(['fixed' => 'right', 'align' => 'center', 'toolbar' => '#rightBtn', 'title' => '操作', 'width' => 150])
            ->clearTable();

        return TableBuilder::getInstance()
            ->addColumns($tableFront)
            ->addSwitchTool([['name' => 'status', 'pk' => 'id', 'text' => '显示|隐藏']])
            ->addTopButtons(['add' => ['width' => 800, 'height' => 600]])
            ->addRightButtons(['edit' => ['width' => 800, 'height' => 600], 'delete'])
            ->addExtraHtml(['CollegeCate'])
            ->addSortTool([['name' => 'sort', 'pk' => 'id', 'url' => url('update')->build()]])
            ->setSearch($this->setSearch(), false)
            ->fetch();
    }

    public function setSearch()
    {
        return TableFront::getInstance()
            ->setSearch(['title', '名称', 'input', '', '', '', 'like']);
    }
}
